/**
 * 
 */
;

function $(selector) {
	if(selector === undefined) return;
	var match = null;
	//#id
	if(match = selector.match(/^#(.+)/)) {
		return document.getElementById(match[1]);
	}
	//.class
	if(match = selector.match(/^\.(.+)/)) {
		return document.getElementsByClassName(match[1])[0];
	}
	//div
	if(match = selector.match(/^([a-zA-Z][a-zA-Z0-9]+)$/)) {
		return document.getElementsByTagName(match[1])[0];
	}
	//div[index = 8]
	if(match = selector.match(/^([a-zA-Z][a-zA-Z0-9]+)\[(.+)\=(.+)\]$/)) {
		var eles = $$(match[1].trim());
		return eles.filter(function(item, index, arr) {
			return item.getAttribute(match[2].trim()) == match[3].trim();
		});

	}
}

function $$(selector) {
	if(selector === undefined) return;
	var match = null;
	//.class
	if(match = selector.match(/^\.(.+)/)) {
		return Array.from(document.getElementsByClassName(match[1]));
	}
	//div
	if(match = selector.match(/^([a-zA-Z]+[0-9]?)$/)) {
		return Array.from(document.getElementsByTagName(match[1]));
	}
	//div[index = 8]
	if(match = selector.match(/^([a-zA-Z]+[0-9]?)\[(.+)\=(.+)\]$/)) {
		console.log(match);
		var eles = $$(match[1].trim());
		return eles.filter(function(item, index, arr) {
			return item.getAttribute(match[2].trim()) == match[3].trim();
		});

	}
}
eventUtils = {
	addEvent: function(ele, eventName, callback, isCapture) {
		if(ele.addEventListener) {
			ele.addEventListener(eventName, callback, !!isCapture);
			eventUtils.addEvent = function(ele, eventName, callback, isCapture) {
				ele.addEventListener(eventName, callback, !!isCapture);

			}
		} else {
			ele.attachEvent(eventName, callback);
			eventUtils.addEvent = function(ele, eventName, callback) {
				ele.attachEvent(eventName, callback);

			}
		}

	},
	removeEvent: function(ele, eventName, callback) {
		if(ele.removeEventListener) {
			ele.removeEventListener(eventName, callback);
			eventUtils.removeEvent = function(ele, eventName, callback) {
				ele.removeEventListener(eventName, callback);
			}
		} else {
			ele.detachEvent(eventName, callback);
			eventUtils.removeEvent = function(ele, eventName, callback) {
				ele.detachEvent(eventName, callback);

			}
		}
	}
}
randomUtils = {
	int: function(min, max) {
		if(max === undefined) {
			var max = min;
			var min = 0;
		}
		return Math.round(Math.random() * (max - min)) + min;
	},
	color:function(){
		return "rgb("+randomUtils.int(255)+","+randomUtils.int(255)+","+randomUtils.int(255)+")";
	}

}